package kercar.manager;

import java.net.InetAddress;

public class WebManager {
	
	/************************************************************************* BLOCK
	 * ATTRIBUTES
	 *******************************************************************************/
	
	private boolean _ping = false;
	private int _time = 10000;

	/************************************************************************* BLOCK
	 * CONSTRUCTOR
	 *******************************************************************************/
	
	public WebManager() {
	}

	/************************************************************************* BLOCK
	 * PUBLIC METHODS
	 *******************************************************************************/
	
	/**
	 * Check if the robot is connected
	 */
	public boolean isConnected() {
		try {
			_ping = InetAddress.getByName("www.google.fr").isReachable(2000);

			// If the connection is not reachable maybe the robot is connecting
			if (!_ping) {
				Thread.sleep(_time);
				_ping = InetAddress.getByName("www.google.fr")
						.isReachable(2000);
			}
		} catch (Exception e) {
			return false;
		}
		return _ping;
	}
	
}
